Jump to content

[SOLVED] form question


wkilc

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/86987-solved-form-question/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444807
Share on other sites

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444810
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/86987-solved-form-question/#findComment-444817
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.