Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question <script> tags inside onClick

    Code:
    onclick="<script language='javascript'>bAdult=true</script>javascript: confirmedok();"
    Is this valid? I want to set a variable value for the function confirmedok to work with?

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,536
    Thanks
    3
    Thanked 513 Times in 500 Posts
    onclick="bAdult=true;confirmedok();"

    is correct

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post

    Unhappy

    I have this ASP/JavaScript code.

    How do i pass the value of 'adult' to the JavaScript which is client-side and ABOVE this ASP?

    This is what i have so far.....

    Code:
    <script language="javascript>
    
    function confirmedok()
    {
    	adult = "<%=adult%>"
    	alert("adult = " + adult);
    
    ... more code......
    
    }
    </script>
    
    <%
    '... if there are NO CHILDREN AND NO INFANTS
    if noc = 0 and noi = 0 then
    response.write "ADULTS"
    adult="yes"
    response.write "adult = " & adult & "<br>"
    %>
    
    <img src="images/confirm.gif" onclick="javascript: confirmedok();"
    onMouseOver='style.cursor="hand"' value="Confirm">&nbsp;&nbsp; 
    <% end if %>
    Not sure if this is in the correct forum

    :-(

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Is this what you want?

    Code:
    function confirmedok(adult)
    {
       alert("adult = " + adult);
       ... 
    }
    ...
    onclick="confirmedok('<%=adult%>');"
    But if there will only be one instance calling the confirmedok() function, then you don't need the parameter and just like what you did, embed the asp variable directly inside the javascript function.
    Code:
    function confirmedok()
    {
       var adult = "<%=adult%>";
       alert("adult = " + adult);
       ... 
    }
    ...
    onclick="confirmedok();"
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post

    Thumbs up

    This solved the problem for those ineterested.......

    Code:
    // WHEN THERE IS JUST AN ADULT TRAVELLING
    function adt()
    {
    	adult = "yes"
    }
    
    
    
    function confirmedok()
    {
    
    	if(adult=="yes")
    	{
    		document.form.TK.value=document.form.TK.value;
    		check(document.form);
    	}
    	
    	if(adult!="yes")
    	{
    
    		..... run some code .....
    
    	}
    
    
    }
    
    ... onClick="javascript: adt(); confirmedok();" ....

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Why not simply this?
    Code:
    function confirmedok(isAdult)
    {
    	if(isAdult)
    	{
    		'..... run some code .....
    	}
    	else
    	{
    		'..... run some code .....
    	}
    }
    ...
    onClick="confirmedok(true);"
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •