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
  HELP: Come And Help Me With This Code Dilfgem 13 209 05-23-2018, 10:18 AM
Last Post: LoyalZeddy
  HELP: Please Help Me With Good Working Media Query To Hide Pc Content From Mobile rocklife22 2 80 09-26-2017, 08:07 PM
Last Post: Deelino
  ALERT:  Webmasters Why Is This Code Not Compiling. Evinsian 7 270 08-10-2017, 09:13 AM
Last Post: Evinsian
  FUN: Let Know Who Can Get This Code Gbedu 7 234 07-08-2017, 05:58 PM
Last Post: Topkeh
  HELP: Webmasters How Do I Add This Function To My Website davincin20 14 443 05-11-2017, 05:15 PM
Last Post: bfaschat
  HELP: Please Help Me Fix This Code jonath45 6 312 03-15-2017, 04:42 PM
Last Post: iamdannyfc
  Hello Coders , I Need This Code/script brainbaze 0 235 03-13-2017, 11:25 AM
Last Post: brainbaze
  Please Help With This Code Macloaded 0 124 01-21-2017, 11:33 PM
Last Post: Macloaded
  I Need Help With This JQuery Code maximus 6 300 01-04-2017, 06:12 PM
Last Post: maximus
  Shortest Code For Random Number Between 1 And N In Javascript dealwap 2 218 01-03-2017, 11:54 AM
Last Post: Aphatheology



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