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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.