Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing javascript string as a parameter 1

Status
Not open for further replies.

ttrinh

MIS
Jan 21, 2002
93
AU
Hi
How do I pass a string variable into a function without generating errors?
Currently I have a variable called TaskDesc which gets passed to my js function. If TaskDesc contains one word all is fine but when TaskDesc contains many words which is the most likely scenario I get errors and the function won't work.
I have tried fiddling with the \ (slash ) but that didn't seem to work.

Any help is appreciated

 
Pliz, give the call and function code with the value of your string. Water is not bad as soon as it stays out human body ;-)
 
Thanks for looking.
This is the function call:
fldNewPriority = &quot;<img alt='Priority 1' class=butClass src=images/s-number-1.gif onMouseOver=selOn(this) onMouseOut=selOff(this) onMouseDown=selDown(this) onMouseUp=selUp(this) onClick=doClick(1,&quot; + fldREQID + &quot;,'&quot;+fldDescription +&quot;') >&nbsp&quot;;

This is the function:
function doClick (newPosition, TaskID , TaskDesc)
{
var oldPosition = 5;
var newTaskID = new Array(5);
var newTaskDesc = new Array(5);

for (var i = 1; i <= 5; i++ )
{
if ( TaskID == document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Priority&quot;+i).value) { oldPosition = i;}
newTaskID[i-1] = document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Priority&quot;+i).value;
newTaskDesc[i-1] = document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Desc&quot;+i).value ;
}


if ( oldPosition > newPosition )
{
newTaskID[newPosition-1] = TaskID;
newTaskDesc[newPosition-1] = TaskDesc;
for (var i = newPosition; i < oldPosition; i++ )
{
newTaskID = document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Priority&quot;+(i)).value;
newTaskDesc = document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Desc&quot;+(i)).value;
}
}
else
{
newTaskID[newPosition-1] = TaskID;
newTaskDesc[newPosition-1] = TaskDesc;
var i = 0;
for (i = oldPosition ; i < newPosition; i = i + 1 )
{
var iplusone = i + 1;


newTaskID[i-1] = document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Priority&quot;+iplusone).value;


newTaskDesc[i-1] = document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Desc&quot;+(i+1)).value;


}
}

for (var i = 1; i <= 5; i++ )
{
document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Priority&quot;+i).value = newTaskID[i-1];
document.forms(&quot;Tasks_Priority&quot;).elements(&quot;Desc&quot;+i).value = newTaskDesc[i-1];

}
 
1st of all, you've got to put all the attributes values of your image tag between quotes. You also got to put a semicolon after each JScript call. So replace this :
Code:
fldNewPriority = &quot;<img alt='Priority 1' class=butClass src=images/s-number-1.gif onMouseOver=selOn(this) onMouseOut=selOff(this) onMouseDown=selDown(this) onMouseUp=selUp(this) onClick=doClick(1,&quot; + fldREQID + &quot;,'&quot;+fldDescription +&quot;') > &quot;;
by this :
Code:
fldNewPriority = &quot;<img alt='Priority 1' class=\&quot;butClass\&quot; src=\&quot;images/s-number-1.gif\&quot; onMouseOver=\&quot;selOn(this);\&quot; onMouseOut=\&quot;selOff(this);\&quot; onMouseDown=\&quot;selDown(this);\&quot; onMouseUp=\&quot;selUp(this);\&quot; onClick=\&quot;doClick(1,&quot; + fldREQID + &quot;,'&quot;+fldDescription +&quot;');\&quot; >&quot;;

In order to verify the format and value of all the parameters received by your function, put these three lines at the top of your function :
Code:
alert (&quot;newPosition = [&quot; + newPosition + &quot;]&quot;);
alert (&quot;TaskID = [&quot; + TaskID + &quot;]&quot;);
alert (&quot;TaskDesc = [&quot; + TaskDesc + &quot;]&quot;);
Water is not bad as soon as it stays out human body ;-)
 
Ur the best !!!!!
Thanks so much it worked !!!
I didn't have to put the alerts in . Just putting the quotes and slashes where you indicated did the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top