Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

javascript values

I have a piece of javascript that creates an array from form imput.  However, the array only updates if you hit refresh, it does not update upon submit.
Avatar of nap0leon
nap0leon

Can we see your code?
Avatar of Robert Granlund

ASKER

The bracketed "IF" statements are from the CMS:

{if option_field == "ad_society_1" OR option_field == "ad_society_2" OR option_field == "ad_society_3" OR option_field == "ad_society_4" OR option_field == "ad_society_5"}
	 	
		{if option_field == "ad_society_1"}
	 	
			<tr>
				<td width="150"><span class="red">*</span><label>{option_label}</label></td>
				<td width="250">{select id="societyonea"}<option {selected} value="{option_value}">{option_name}</option>{/select}</td>
				<td width="150"><div id="society_div"> </div></td>
			</tr>
		{/if}
		
		
		{if option_field == "ad_society_2"}
	 	
			<tr>
				<td width="150"><label>{option_label}</label></td>
				<td width="250">{select id="societytwoa"}<option {selected} value="{option_value}">{option_value}</option>{/select}</td>
				<td width="150"><div id="society_div"> </div></td>
			</tr>
																		
		{/if}
		
		{if option_field == "ad_society_3"}
	 	
			<tr>
				<td width="150"><label>{option_label}</label></td>
				<td width="250">{select id="societythreea"}<option {selected} value="{option_value}">{option_value}</option>{/select}</td>
				<td width="150"><div id="society_div"> </div></td>
			</tr>

		{/if}
		
		{if option_field == "ad_society_4"}
	 	
			<tr>
				<td width="150"><label>{option_label}</label></td>
				<td width="250">{select id="societyfoura"}<option {selected} value="{option_value}">{option_value}</option>{/select}</td>
				<td width="150"><div id="society_div"> </div></td>
			</tr>

		{/if}
		
		{if option_field == "ad_society_5"}
	 	
			<tr>
				<td width="150"><label>{option_label}</label></td>
				<td width="250">{select id="societyfivea"}<option {selected} value="{option_value}">{option_value}</option>{/select}</td>
				<td width="150"><div id="society_div"> </div></td>
			</tr>
<script type="text/javascript">         
var arr3 = ['societyonea','societytwoa','societythreea','societyfoura','societyfivea'];
var arr4 = new Array();
for(var i=0;i<arr3.length;i++){
    arr4[i] = $('#'+arr3[i]).val();
}
var societyb = arr4.join(',');
document.write('<input type="hidden" id="hiddenelementb" name="custom_data[society_search_1]" value="'+societyb+'">');
document.write(societyb);
</script>	
		{/if}

	{/if}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of experts1
experts1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
all that does is give me a list of the five input ids, not the chose values
It looks like your script is only being executed in-line when the page loads. Is your submit button set up to execute the script again when clicked?
@xmediaman:  How do you do that?
There are actually several ways...

with an onclick event on the submit button
<input type="submit" value="SUBMIT" id="submitBtn" onclick="javascript: executeCode();">

Open in new window


with an onsubmit event on the form
<form name="form1" action="/#' method="post" onsubmit="javascript: executeCode();">

Open in new window


or using the DOM in your javascript
document.form1.submitBtn.onsubmit = executeCode;

Open in new window


With either of these situations, though, your script would need to be in a function to be called at the appropriate time. As it is now, it can only execute when the page loads.
What do you think is wrong with the:

<form id="update_cart_form" onsubmit="javascript: executeCode(); && return validateForm(this);" action="MY ACTION" method="post">

It will update but skips validation
<form id="update_cart_form" onsubmit="executeCode(); return validateForm(this);" action="MY ACTION" method="post">


or try this


<form id="update_cart_form" onsubmit="return (executeCode() && validateForm(this));"
Please post the full client side code for the form!