calling a function with a string argument in 'onblur'

problem with passing the argument in the text input tag

Page 1 of 1

5 Replies - 9759 Views - Last Post: 18 August 2010 - 01:14 AM

#1 nkasei28   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 93
  • Joined: 10-May 09

calling a function with a string argument in 'onblur'

Posted 17 August 2010 - 02:47 PM

Hi there. Now here is my problem. I want to call a function in the onblur event of an input text tag and pass a string to it as an argument. I'm having problem with how to pass it...whether to use single quotes or double quotes. Here is my code:
<html>
<head>
<script type="text/javascript">
 
 function default_value(field,stringValue)
 {
  field.value=stringValue;
 }
</script>

</head>
<body>

<form>
<input type="text" onblur="default_value(this,'single qoute or double qoute for string?")>
</form>

</body>
</html>



Should I use single quotes or double quotes when passing the string argument to the function? Thanks in advance for your help

This post has been edited by nkasei28: 17 August 2010 - 02:49 PM


Is This A Good Question/Topic? 0
  • +

Replies To: calling a function with a string argument in 'onblur'

#2 moopet   User is offline

  • binary decision maker
  • member icon

Reputation: 343
  • View blog
  • Posts: 1,189
  • Joined: 02-April 09

Re: calling a function with a string argument in 'onblur'

Posted 17 August 2010 - 03:00 PM

There's very little difference. You just make sure you don't nest double inside double without escaping them (or the same for single)
What you've got is fine (except you left off the ending double-quote)
Was This Post Helpful? 0
  • +
  • -

#3 nkasei28   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 93
  • Joined: 10-May 09

Re: calling a function with a string argument in 'onblur'

Posted 17 August 2010 - 03:19 PM

View Postmoopet, on 17 August 2010 - 02:00 PM, said:

There's very little difference. You just make sure you don't nest double inside double without escaping them (or the same for single)
What you've got is fine (except you left off the ending double-quote)


I tried this and it wouldn't work.
<input type="text" onblur="default_value(this,"year")">

Was This Post Helpful? 0
  • +
  • -

#4 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: calling a function with a string argument in 'onblur'

Posted 17 August 2010 - 03:22 PM

you've got nested double quotes there, you either need to escape your inside quotes or use single quotes.
Was This Post Helpful? 0
  • +
  • -

#5 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: calling a function with a string argument in 'onblur'

Posted 17 August 2010 - 03:31 PM

<input type="text" onblur="default_value(this,'year')">



or

<input type="text" onblur='default_value(this,"year")'>



or

<input type="text" onblur="default_value(this,\"year\")">


Was This Post Helpful? 0
  • +
  • -

#6 moopet   User is offline

  • binary decision maker
  • member icon

Reputation: 343
  • View blog
  • Posts: 1,189
  • Joined: 02-April 09

Re: calling a function with a string argument in 'onblur'

Posted 18 August 2010 - 01:14 AM

View Postnkasei28, on 17 August 2010 - 09:19 PM, said:

View Postmoopet, on 17 August 2010 - 02:00 PM, said:

There's very little difference. You just make sure you don't nest double inside double without escaping them (or the same for single)
What you've got is fine (except you left off the ending double-quote)


I tried this and it wouldn't work.
<input type="text" onblur="default_value(this,"year")">


This is exactly what I said you couldn't do. What you had originally was fine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1