PwnageAtPwn
PwnageAtPwn

Reputation: 431

Javascript code not being called/ not working properly

I have this javascript code:

<script type="text/javascript">
function editHiddenInput(CarType)
{
 document.getElementById('sellingcarname') = CarType;
}

</script>

Hidden Input:

<input name="sellingcarname" id="sellingcarname" type="hidden" value="" />

Once it's called it's supposed to change the hidden input(sellingcarname) to text defined when the function is called using this button:

<div id="button"><input type="submit" onclick="editHiddenInput('rtv');" value="Sell" style="display: none; " /><span class="button">Sell<span></span></span></div>

However, it does not change the hidden input, so it's pretty useless, any help?

Upvotes: 1

Views: 96

Answers (3)

Ahmet Can G&#252;ven
Ahmet Can G&#252;ven

Reputation: 5462

Try this

You need to put your function code noWrap(Head).

document.getElementById('sellingcarname').value = CarType;

You can change your hidden inputs value with this code.

Upvotes: 0

danludwig
danludwig

Reputation: 47375

Try

document.getElementById('sellingcarname').value = CarType;

Update

Sorry, I missed a couple other things with this code.

When you click on the submit button, if it is in a form, it will submit the form, and the next page load will clear out the value you set. Make sure you have this in your onclick attribute:

<input type="submit" 
    onclick="editHiddenInput('rtv'); return false;" 
    value="Sell" style="display: none; " />

Upvotes: 3

Guffa
Guffa

Reputation: 700730

You are trying to assign the string to the element itself, you have to assign it to the value property:

document.getElementById('sellingcarname').value = CarType;

Upvotes: 1

Related Questions