Hi guys, not sure if this is a good methodology but I ran into a snag that I thought I'd get your advice on.
I have a form. PHP will process it.
The variables in the previous pages are passed through JS in the URL string to get to the page displaying the form.
Since I can't use text() to set a hidden value in a form and val() only gets from a form item, how could I set the 2 js variables into the form so that I can simply treat them like they were processed as part of the form like any form item?
My first idea was to have hidden inputs and use text() to set them. It doesn't work.
ideas?
Never mind.......
this.form.elements["formelementname"].value = arrayname[1];
val() is a jQuery thing so I assume you're using that. If so, val(something) will set the val on an input.
yup got jQuery going....
I read the docs and it said val() was get and not set.
Am I an idiot or is it best to assume docs aren't detailed documents? Both?
fuck
http://api.jquery.com/val/ (scroll halfway down the page to val(value))
It's not layed out too well, but it's there.
well fuck me up the goat ass......
I gotta scroll??!!! hahaha thanks stinky. You rock man.
Suggestion....should I change it to val()? Is there any difference code-wise?
[edit] So, my first try is pure JS and my second is jQuery? Correct? Incorrect?
set:
plain js : formElement.value = 'stringvalue';
jquery : $(formElement).val('stringvalue');
get :
plain js : var sValue = formElement.value;
jquery : var sValue = $(formElement).val();
Plain js should be faster if you don't have to wrap the element. Jquery has benefits if you also have to account for radiobuttons, checkboxes etc, especially crossbrowser.
wish I had your guys' knowledge......thanks.
Stumbling block #2.
$(document).ready(function(){
var cost = <?php $cost ?> ;
$('#12').hide();
$('#18').hide();
$('#20').hide();
$('#30').hide();
$('#.cost.').show;
});
How can I get it to turn on the PayPal button div based upon the cost? In Firebug I get the variable from PHP no problem. I simply want to show() the correct button based upon the cost value. This line doesn't work: $('#.cost.').show; and I've tried ([cost]) (cost) $cost.
edit....now it's not showing cost. I hate coding!! ARGH! 
$('#' + cost.toString()).show();
thanks stickman...it works nicely.
Now if I can figure out why: var cost = <?php $cost ?> ; stopped working.
edit | I moved the PHP code INTO the script block and it works now. I'm not sure what the difference is and I could use advice but it at least works now. ++
Difficult to say without seeing the rest of your code. Happy to take a look if you want to post or PM it.
var cost = <?php $cost ?>
should be
var cost = <?php echo $cost ?>
I need some serious testing help.
HTML5 form elements with 'required' are not stopping the user from proceeding to the PHP page. If anyone could help me figure out 'required' for Safari I'd appreciate it.
http://design.reckseidler.com/testing/
Firefox makes the user fill out the required fields. Safari does not. I have no idea what IE or Chrome are doing yet.
it's like my Safari is operating in HTML4 mode and 'required' isn't being read!! ARGH!!! I fucking hate web.
NEVER MIND!!!!!!!
http://www.w3schools.com/html5/att_input_required.asp
Safari and IE chose not to read the 'required' attribute when choosing what HTML5 standards to follow.
THIS is why I fucking HATE web development. I have to write HTML4/JS code to do what HTML5 was supposed to do? WTFF? Safari was the one bragging about being HTML5ish first. I don't get it. I have to write a javascript validation because they couldn't make required work?
Originally posted by Storm
I have to write a javascript validation because they couldn't make required work?
yes, you could do that, or use this
May I suggest:
var cost = parseInt('<?php echo $cost ?>');
Reason is that if the cost var has no value (ie, is null or empty), the js will break. Using my method, the js will not break - the var will be parseInt of an empty string leaving you to set a default value:
var defaultValue = 10;
var cost = isNaN(parseInt('<?php echo $cost ?>')) ? defaultValue : parseInt('<?php echo $cost ?>');
If cost is not a number then that will default to 10;
Originally posted by dwadwee
yes, you could do that, or use this
DEFINITELY use the jquery validation.
It is a bit intimidating to read the documentation (which is not very clear in my opinion) but you can do it as simply as adding "required" css class to each input that you want validated.
Also quite a few of us have built custom validation on top of the jquery validatiosn and can steer you through the process.
Thanks guys. I've written validation before its just not something I do a lot. Help is appreciated.
My frustration is that we already had the conversation elsewhere how HTML5 is just going to save the world. But here's a good example where implementation is a failure. I got the client to accept HTML5 as a standard and not to worry about older browsers (because the target is students) so part of my quote is to NOT include my time in writing custom form validation routines because HTML5 has it covered with the 'required' attribute and placeholder and just so many thing to make it easier and better on us. Then you run into reality. It's frustrating. jQuery is to me what Flash is. It is a way to standardize development through a framework. At this point HTML5 doesn't kill or replace Flash....hell it doesn't even kill or replace jQuery.
So, this site was intended to be all HTML5. Now it's HTML4.8 and I look bad. That's where my frustration lies.
But having you guys here is a good hug for my designer mind.
[edit] I just went to that link above. Trying to submit the form does NOTHING for me. First click, it opened jQuery docs in the iwindow. Second click sits there. Does this mean it won't work in FF 8.0.1?
[edit edit] Wow the documentation sucks incredibly as you've said. Holy fuck I hope someone didn't get paid to write that shit.
http://caniuse.com/#feat=form-validation
Note: Partial support in Safari refers to lack of notice when form with required fields is attempted to be submitted.
Seems all major browsers support validation with through the property, but only Safari indeed lacks a prompt/modal. Maybe you can work around just that issue ?
Had that thought and it's good advice. I think IE will be an issue if new students show up for school with their shiny new Windows 7 laptop and they just run with IE.
I'll admit I've been confused because I've actually gone to sites that said 'required' works in all major browsers or even specifically said 'Works in Safari' so I don't know who to trust anymore with these plug-ins. If I go to test on my computer with the latest FF and Sa neither form validates for me. They go to the jQuery page as a link.
For Safari, 'required' doesn't validate at all it isn't simply that you don't get the pop-ups. It actually goes to the PHP page. It doesn't even stop to think about it.
Does the form in dwadwee's link work for you guys? It doesn't work for me in FF or Safari.
Those examples didn't work but this plug-in works nicely in my code. Thanks.
It fails on my android phone, but I am certain it works on all major browsers. I'll do a proper cross browser check tomorrow.
heh looks like that demo is farked - but the plug in works, no question there. It's the way to go, fo sho.
yup got it running.....I was worried when the demos were farked but all good. Luv the suggestion. Thanks!
DWADWEE, help me!!!!!
it doesn't validate in IE......at all......IE8 or IE9. Is it me?