Changing Hidden Input's Name based on country of origin

Changing Hidden Input's Name based on country of origin, which is

Page 1 of 1

2 Replies - 763 Views - Last Post: 03 September 2009 - 11:56 PM

#1 bluecure  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-September 09

Changing Hidden Input's Name based on country of origin

Posted 03 September 2009 - 06:25 PM

Hi all,

I'm trying, so far unsuccessful to make a function to change the name of a hidden input based upon the country of the user, i have some php code that determines there country of origin of the user fine. I then have a small java script function to change the name of the hidden input depending on the country of origin.
The php variable that holds the country of origin is $country; that variable then needs to be assigned to x in my java script function. $country is equal to AU if your in Australia and US if your in America.

<script type = "text/javascript">

function changelist() {
var x = "<?php echo $country;?>";

if (x == "AU") {
document.getElementById("theHiddenInput").name = "SelectLists[41]"};

else if (x == "US") {
document.getElementById("theHiddenInput").name = "SelectLists[43]"};

}

</script>

<input type="hidden" id="theHiddenInput" name="SelectLists[41]" value="Yes">



If anyone has any tips or pointers as to what I'm doing wrong, I'd greatly appreciate it,

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Changing Hidden Input's Name based on country of origin

#2 CamoDeveloper  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 20
  • View blog
  • Posts: 250
  • Joined: 12-June 09

Re: Changing Hidden Input's Name based on country of origin

Posted 03 September 2009 - 10:49 PM

You're setting it as a string, have you tried just doing:
var x = <?php echo $country;?>;?

~Camo
Was This Post Helpful? 0
  • +
  • -

#3 bluecure  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-September 09

Re: Changing Hidden Input's Name based on country of origin

Posted 03 September 2009 - 11:56 PM

Hey CamoDeveloper thanks for the reply,

I tried what you said, and
 var x = <?php echo $country;?>; 
is working, its receiving the correct value (AU), However that value is not replacing the hidden inputs name. Any ideas?


Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1