Home Need to change the value of a variable using javascript
Reply: 1

Need to change the value of a variable using javascript

user1152652
1#
user1152652 Published in 2018-02-13 20:40:54Z

I have dug and dug for a few hours today without much luck. My language is PHP and my javascript skills are not that great I am learning.

I have a list of buttons, each with their own value. When the button is pressed I would like for it to send the value of that button to a variable so the right file is loaded.

I know that this has got to be a simple thing but it's beyond me right now.

Code:

<button type="button" id="myButton" onClick="setval('shannen')" class="btn btn-primary cd-btn">VIEW</button>

<button type="button" id="myButton" onClick="setval('fall-features')" class="btn btn-primary cd-btn">VIEW</button>

var content_div = document.getElementsByClassName("cd-panel-content"); 
$(document).ready(function() {
    setValue();
    $("#myButton").on('click',setValue)
}) console.log(mysample);

 function setValue() {
    mysample=null;
    var mysample=$("#myButton").val();
    var mysample=mysample+".html";
    console.log(mysample);
$(".cd-panel-content").load("emails/"+mysample);

When they click it a window opens on the right of the screen displaying an HTML file.

www.jeffcade.com to see the functionality. I have gotten it to work with one variable but then it will not change when a different button is pressed.

Dan Raps
2#
Dan Raps Reply to 2018-02-13 20:49:52Z

You're calling a "setval()" function with one argument, but you've written a "setValue()" function with no arguments. You could try changing your function to:

function setval(mySample) {
    mySample=mySample+".html";
    console.log(mySample);
$(".cd-panel-content").load("emails/"+mySample);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310776 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO