Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP: Why Is This Code Not Working. Webmasters Check In!
#1
The aim of the code is to use function argument as object properties:


<html>
<head>
<script>
function name(fname, lname, bname, gname) {
var x={firstName:fname, lastName:lname, bigName:bname, goodName:gname};
var f, l, b, g;
f= x.firstName;
l= x.lastName;
b= x.bigName;
g= x.goodName;
window.alert(""+f+","+l+","+b+","+g+"");
}
</script>
</head>
<body>
<button onclick="name("Prince", "Adigwe", "The Preditor", "mr");">Click to run Function</button>
<div id="div" onload="name;">
</div>
</body>
</html>
[-] The following 1 user Likes Thepreditor's post:
  • dealwap
#2
What's the error feedback?
It takes so long to learn simplicity.
Reply
#3
(08-15-2017, 09:09 PM)Dealwap Wrote:
What's the error feedback?


The page just reloads. I have tried using a different event:
<body onload="name("Prince", "Adigwe", "The Preditor", "Mr");">
but nothing happens
Reply
#4
(08-15-2017, 09:42 PM)Thepreditor Wrote:
The page just reloads. I have tried using a different event:
<body onload="name("Prince", "Adigwe", "The Preditor", "Mr");">
but nothing happens

You don't need the onload for anything since the button needs to be clicked to show the alert();
It takes so long to learn simplicity.
Reply
#5
@Thepreditor your
window.alert(""+f+","+l+","+b+","+g+"");
should be
window.alert("'+f+','+l+','+b+','+g+,");
and your
<button onclick="name("Prince", "Adigwe",
"The Preditor", "mr");">Click to run
Function</button>

should be

<button onclick="name('Prince', 'Adigwe',
'The Preditor', 'mr');">Click to run
Function</button>
[-] The following 1 user Likes jonath45's post:
  • samarys
Reply
#6
(08-16-2017, 05:51 AM)jonath45 Wrote:
@Thepreditor your
window.alert(""+f+","+l+","+b+","+g+"");
should be
window.alert("'+f+','+l+','+b+','+g+,");
and your
<button onclick="name("Prince", "Adigwe",
"The Preditor", "mr");">Click to run
Function</button>

should be

<button onclick="name('Prince', 'Adigwe',
'The Preditor', 'mr');">Click to run
Function</button>


i have tried it, but still the same result. I guess it did not work because we are using a Variable(object) to store a Variable(Function Argument).
Reply
#7
(08-16-2017, 08:56 PM)Thepreditor Wrote:
i have tried it, but still the same result. I guess it did not work because we are using a Variable(object) to store a Variable(Function Argument).


sorry check the window.alert i omitted a (')
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  SHARED: The Working Background Of The $ In Jquery jonath45 2 72 09-22-2018, 09:01 AM
Last Post: jonath45
  HELP: Come And Help Me With This Code Dilfgem 17 454 07-03-2018, 08:58 PM
Last Post: Dilfgem
  HELP: Please Help Me With Good Working Media Query To Hide Pc Content From Mobile rocklife22 2 106 09-26-2017, 08:07 PM
Last Post: Deelino
  ALERT:  Webmasters Why Is This Code Not Compiling. Evinsian 7 335 08-10-2017, 09:13 AM
Last Post: Evinsian
  FUN: Let Know Who Can Get This Code Gbedu 7 281 07-08-2017, 05:58 PM
Last Post: Topkeh
  HELP: Webmasters How Do I Add This Function To My Website davincin20 14 525 05-11-2017, 05:15 PM
Last Post: bfaschat
  HELP: Please Help Me Fix This Code jonath45 6 356 03-15-2017, 04:42 PM
Last Post: iamdannyfc
  Hello Coders , I Need This Code/script brainbaze 0 255 03-13-2017, 11:25 AM
Last Post: brainbaze
  Please Help With This Code Macloaded 0 141 01-21-2017, 11:33 PM
Last Post: Macloaded
  I Need Help With This JQuery Code maximus 6 350 01-04-2017, 06:12 PM
Last Post: maximus



Users browsing this thread: 1 Guest(s)

About Nigeria's Creative Talents

Nigeria's Creative Talents is an online community where every creative Nigerians can share ideas with themselves.

For any more information, please use our contact form.

              User Links

              Advertise