1

I have an input in html form and I need to send them to script. it has both name and id .

 <p>
        <select onchange="myFunction(this.value)"  name="shippcity" id="shippcity">
		
            <option value="0">state</option>
			     	
        </select>
		 <input type="hidden" name="calc_shipping_city" id="shipping_city" value="" />// will be removed

	</p>

<script>
function myFunction(val) {
 if ( val === '' ) {
		 
	}
	else { 
	 //input val to name="calc_shipping_city" and id="shipping_city"
	  document.getElementById("shipping_city").value = val; 
          }

   
}
</script>

there is this code too from woocomerce:

      <?php
}

$my_city = $woocommerce->customer->get_shipping_city();
$my_city = explode('-', $my_city);
if(isset($my_city) && intval($my_city[0]) > 0 ){
    ?>
    set_initial_val('shipp', 'city', <?php echo $my_city[0]; ?>);

1 Answer 1

1

Each input element has a value property which you can set.

function myFunction(val) {
  if ( val === '' ) {

  }
  else {
   document.getElementById("shipping_city").value = val;              
   document.getElementById("shippcity").form.submit();
  }
}
Sign up to request clarification or add additional context in comments.

4 Comments

thanks, I tried this. but it seems the second command doesn't work.(document.getElementById("shippcity").form.submit();) nothing happend onchage.
It's hard to tell from your code example, but your form elements need to live inside of a <form> element for that second line to work. From what I see in your code they only exist inside of a <p> element.
the problem is from shipping_city ID . that line does not work.
thank you very much.problem solved. I shouldn't remove that input line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.