wkilc Posted January 21, 2008 Share Posted January 21, 2008 Hello, I am pretty proficient with HTML, but relatively new to PHP. I have a form where folks select state from a list. I would like to pass along a "hidden" value with a mailing address, specific to the state chosen in the previous list. <form> <select name="r_State" style="height: 22px; width: 180px"> <option value="RI">RI</option> <option value="CT">CT</option> <option value="MA">MA</option> </select> if "r_State"="RI" then <input type="hidden" name="r_State_addy" value="100 Main Street, RI"> if "r_State"="MA" then <input type="hidden" name="r_State_addy" value="45 Farm Street, MA"> if "r_State"="CT" then <input type="hidden" name="r_State_addy" value="45 Poop Street, CT"> </form> I know that this should be possible, with PHP? Or JavaScript? Can anyone nudge me in the right direction? Thanks for reading! ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/ Share on other sites More sharing options...
marcus Posted January 21, 2008 Share Posted January 21, 2008 Javascript can do it. And why does Connecticut get "Poop Street," I live in that state, not fair. Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444797 Share on other sites More sharing options...
The Little Guy Posted January 21, 2008 Share Posted January 21, 2008 first off you your using the wrong syntax, that looks like it is VB Script syntax. instead of if/then use if/else instead of = use == Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444798 Share on other sites More sharing options...
marcus Posted January 21, 2008 Share Posted January 21, 2008 Lol, he's just showing us an example that if what they selected the hidden value changes to that. Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444800 Share on other sites More sharing options...
wkilc Posted January 21, 2008 Author Share Posted January 21, 2008 Thank you... I don't suppose anyone could help me write the first function? :-\ ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444802 Share on other sites More sharing options...
priti Posted January 21, 2008 Share Posted January 21, 2008 Hi, Fromwhere you are populating your values '100 Main Street, RI' if you select RI. or 45 Farm Street, MA if you select MA are you trying to club input fields and create a hidden address fields??? Try to do it in javascript something like function create_add(frm) { var address; address=frm.street.value+frm.state.value; document.getElementById('hiddenaddress').value=address; } In php When you will post your code you will get evrything in $_POST so you can concatenate there. have a gr8 day Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444807 Share on other sites More sharing options...
wkilc Posted January 21, 2008 Author Share Posted January 21, 2008 Thanks again. I don't know JavaScript. Sometimes I can canabilize existing code and tweak it a little: if ( formobj.elements['r_State'].value.indexOf( "RI" ) != -1 ) then ( formobj.elements['r_State_addy'].value.indexOf( "100 Main Street, RI" ) != -1 Am I even close? ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444810 Share on other sites More sharing options...
The Little Guy Posted January 21, 2008 Share Posted January 21, 2008 Like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/javascript"> function getIPut(val){ var state = document.getElementById('r_State').value; var loca; if(state == 'RI'){ loca = '100 Main Street, RI'; }else if(state == 'CT'){ loca = '45 Poop Street, CT'; }else if(state == 'MA'){ loca = '45 Farm Street, MA'; } document.getElementById('stateT').value = loca; } </script> </head> <body> <form> <select onchange="getIPut();" id="r_State" name="r_State" style="height: 22px; width: 180px"> <option>Please Select...</option> <option id="RI" value="RI">RI</option> <option id="RI" value="CT">CT</option> <option id="RI" value="MA">MA</option> </select> <input id="stateT" type="hidden" name="r_State_addy"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444817 Share on other sites More sharing options...
wkilc Posted January 21, 2008 Author Share Posted January 21, 2008 Thanks very much! That was above and beyond. Unfortunately, as I'm testing it, it's not passing the data along... probably my fault... still workin' on it. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444825 Share on other sites More sharing options...
wkilc Posted January 21, 2008 Author Share Posted January 21, 2008 <input id="stateT" type="hidden" name="r_State_addy"> Wait a sec... does this need a "value" defined... or is that taken care of by the script? ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444831 Share on other sites More sharing options...
wkilc Posted January 21, 2008 Author Share Posted January 21, 2008 Never mind! My own ignorance. It works beautifully. Thanks very much... next time I bake cookies, I'll have to send you some. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444836 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.