0

I have a function as below in javascript that gets all the values from different inputs/selects. It must then build up a string that will be passed to a textarea.

This was working fine last night when I tested. I then tweaked something, not sure what I did and of course as per Murphy, it won't work anymore...

<script type="text/javascript"> 
function updateText() { 
    var sel1= document.getElementById('vehicleyear'); 
    var sel2= document.getElementById('make');
    var sel3= document.getElementById('model');
    var sel4= document.getElementById('der');
    var sel5= document.getElementById('price');
    var sel6= document.getElementById('mileage');
    var sel7= document.getElementById('colour');
    var sel8= document.getElementById('intcolour');
    var sel9= document.getElementById('bodytype');
    var sel10= document.getElementById('condition');
    var sel11= document.getElementById('features');

    var selValue1 = sel1.options[sel1.selectedIndex].value;
    var selValue2 = sel2.options[sel2.selectedIndex].value;
    var selValue3 = sel3.options[sel3.selectedIndex].value; 
    var selValue4 = sel4.options[sel4.selectedIndex].value;
    var selValue5 = document.getElementById('price').value;
    var selValue6 = document.getElementById('mileage').value;
    var selValue7 = sel7.options[sel7.selectedIndex].value;
    var selValue8 = sel8.options[sel8.selectedIndex].value;
    var selValue9 = sel9.options[sel9.selectedIndex].value;
    var selValue10 = sel10.options[sel10.selectedIndex].value;
    var selValue11 = document.getElementById('features').value;

    var selValue = selValue1 + " " + selValue2 + " " + selValue3 + " " + selValue4 + " with only " + selValue6 + " kilometers, selling for ONLY R " + selValue5 + ". This " + selValue10 + " " + selValue7 + " with " + selValue8 + " interior " + selValue2 + " " + selValue3 + " has the following features - " + selValue11 + "."; 

    alert(selValue);

    document.form1.comments.value = selValue;
    //I have 2 forms on my page. The form containing comments is called frmadd. I changed form1 to frmadd, still no luck. I have added onchange, onblur, onclick in my textarea, no luck. it was working fine with onchange last night. :(
} 
</script>

<form action="" name="frmadd" id="frmadd" method="POST" class="innertable">

    <textarea cols="50" rows="15" name="comments" id="comments" style="background-color:transparent; border:groove; color:#FFF" onclick="updateText()" onblur="updateText()" onFocus="updateText()">
    </textarea>

</form>
2
Contributors
6
Replies
8
Views
4 Years
Discussion Span
Last Post by AndreRet
0

Yip, just tried it thanx. Still nothing. It's almost like when the textarea gets focus, it does not call the function. I know this because the alert message doesn't even show.

I had the script in my header, moved it to the same table as well, still nothing..

0

I just did a seperate test page and it works fine. I'm at a total loss...

This is the code I used to test that works!!

<html>
<head>
<script>
function displayResult()
{
(document.getElementById("myTextarea").value = document.getElementById("addcomments").value);
}
</script>

<script type="text/javascript"> 
function updateText() { 
    var sel1= document.getElementById('cost1'); 
    var sel2= document.getElementById('cost2');

    var selValue1 = sel1.options[sel1.selectedIndex].value;
    var selValue2 = sel2.options[sel2.selectedIndex].value; 

    var selValue = "This nice car " + selValue1 + ", " + selValue2; 

    document.getElementById('myTextarea').value = selValue;
} 
</script>
</head>
<body>
<form name="form1">
<!--<textarea id="myTextarea" cols="50" onFocus="displayResult()">-->

<br />

<select name="cost" id="cost1" > 
<option>100</option> 
<option>200</option> 
<option>300</option> 
</select>
<select name="cost" id="cost2" > 
<option>400</option> 
<option>500</option> 
<option>600</option> 
</select> 

<textarea id="myTextarea" name="myTextarea" cols="50" onFocus="updateText()">
</textarea>   
</form>
</body>
</html>
0

If the alert doesn't show... does javascript use a maximum line length perhaps. Am not really sure about the answer because I never use such long statements. Can you trace it with the debugger, and see what happens?

Edited by pritaeas

0

Think I found the problem, the length was fine when I hard coded it. The problem lies in getting the values back from the control. If I use the code to get the values for all my select controls, no problem. It stops responding as soon as I add the code to get the values for the text input controls. Anny suggestions here?

var selValue1 = sel1.options[sel1.selectedIndex].value; //Works Fine...
    var selValue2 = sel2.options[sel2.selectedIndex].value; //Works Fine...
    var selValue3 = sel3.options[sel3.selectedIndex].value;  //Works Fine...
    var selValue4 = sel4.options[sel4.selectedIndex].value; //Works Fine...
    var selValue5 = document.getElementById('price').value; //Stops the function from running as soon as set a value...
    var selValue6 = document.getElementById('mileage').value; //Stops the function from running as soon as set a value...

Once I comment them out, I get the values and can build the string which shows fine in my textarea. There is values given for the text inputs, no idea why it does not want to run...

Edited by AndreRet

1

I feel like a real monkey right now. I've added the "price" variable this morning, amongst other stuff. Just saw that price input was given a name, never an id. Once I've added the id, all seemed to run fine. STUPID ME!!!

Thanx for your time pritaeas. You made me go through my code and controls one by one to eliminate the problem. Never too old to learn I suppose. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.