TwelvestoneFront End

JS to Form for PHP processing


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Storm
 
2011-11-09

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?

Storm
 
2011-11-09

Never mind.......

 this.form.elements["formelementname"].value = arrayname[1];
Stinky
 
2011-11-09

val() is a jQuery thing so I assume you're using that. If so, val(something) will set the val on an input.

Storm
 
2011-11-09

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

Stinky
 
2011-11-09

http://api.jquery.com/val/ (scroll halfway down the page to val(value))

It's not layed out too well, but it's there.

Storm
 
2011-11-09

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?

wowbagger[tip]
 
2011-11-09

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.

Storm
 
2011-11-09

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! k

Stickman
 
2011-11-09

$('#' + cost.toString()).show();

Storm
 
2011-11-09

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. ++

Stickman
 
2011-11-09

Difficult to say without seeing the rest of your code. Happy to take a look if you want to post or PM it.

dwadwee
 
2011-11-10

var cost = <?php $cost ?>

should be

var cost = <?php echo $cost ?>

Storm
 
2011-11-28

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.

Storm
 
2011-11-28

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?

dwadwee
 
2011-11-28

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

scudsucker
 
2011-11-29

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;

scudsucker
 
2011-11-29

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.

Storm
 
2011-11-29

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.

wowbagger[tip]
 
2011-11-29

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 ?

Storm
 
2011-11-29

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.

Storm
 
2011-11-29

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.

scudsucker
 
2011-11-29

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.

dwadwee
 
2011-11-29

heh looks like that demo is farked - but the plug in works, no question there. It's the way to go, fo sho.

Storm
 
2011-11-29

yup got it running.....I was worried when the demos were farked but all good. Luv the suggestion. Thanks!

Storm
 
2011-11-30

DWADWEE, help me!!!!!

it doesn't validate in IE......at all......IE8 or IE9. Is it me?

TwelvestoneFront End

JS to Form for PHP processing