• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 63
  • Last Modified:

pass in string to function

Hhw would I pass in a string on button click to my script below?

<button class="button-blue" id="test1" runat="server" onclick="custom1();">Try it</button>

Open in new window



    <script>
        var custom1 = function () {
            uglipop({
                class: 'put', //styling class for Modal
                source: 'html',
                content: '<div><br /><br /><br />There seems to be a problem.<br/>' + vat + '<br /> Please verify your card information.</div>'
            });
        }
    </script>

Open in new window

0
Larry Brister
Asked:
Larry Brister
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Chris StanyonCommented:
Set an argument for your function:

var custom1 = function (yourString) {
    alert(yourString);
    ...

Open in new window

and then pass in the string to the call:

<button class="button-blue" id="test1" runat="server" onclick="custom1('Some Value');">Try it</button>

Open in new window

0
 
Leonidas DosasCommented:
<!DOCTYPE html>
<html>
<head>
<title>HTML, CSS and JavaScript demo</title>
  <script src="https://cdn.jsdelivr.net/npm/uglipop@1.0.0/uglipop.js"></script>
  <style>

    .put{
      border-radius: 10px;
      background-color:white;
      width:300px;
      height:300px;
      padding:10px;
     -webkit-box-shadow: 0px 0px 39px 12px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 39px 12px rgba(0,0,0,0.75);
box-shadow: 0px 0px 39px 12px rgba(0,0,0,0.75);
    }
  </style>
</head>
<body>
<!-- Start your code here -->

<p class="lw">Hello Weaver!</p>
<button class="button-blue" id="test1" onclick="custom1('This is an example string');">Try it</button>
<!-- End your code here -->
  <script>
     var custom1 = function(arg){
       uglipop({class:'put', //styling class for Modal
        source:'html',
        content:'<div>'+ arg+' </div>'});}
  </script> 
  
</body>
</html>

Open in new window

0
 
Julian HansenCommented:
What string do you want to pass and why?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Larry Bristersr. DeveloperAuthor Commented:
I actually went with setting a hidden value and reading from that

Otherwise... the popup kept opening and closing after 1 second.

 <script>
        var ddd = document.getElementById('<%= HiddenStatusFlag.ClientID%>').value;
        var custom1 = function () {
            uglipop({
                class: 'put', //styling class for Modal
                source: 'html',
                content: '<div><br /><br /><br />There seems to be a problem.' + ddd + 'Please verify your card information.</div>'
            });
        }
    </script>

Open in new window

0
 
Leonidas DosasCommented:
var ddd = document.getElementById('<%= HiddenStatusFlag.ClientID%>').value;

function remove(){
  document.getElementById('uglipop_overlay_wrapper').style.display = 'none';
       document.getElementById('uglipop_overlay').style.display = 'none';
        document.getElementById('uglipop_content_fixed').style.display = 'none';
}
var custom1 = function(arg){
 
    if(ddd){
       uglipop({class:'put', //styling class for Modal
        source:'html',
        content:'<div><br /><br /><br />There seems to be a problem. ' + ddd + '  Please verify your card information.</div>'});
    }else{
        uglipop({class:'put', //styling class for Modal
        source:'html',
        content:'<div><br /><br /><br />There seems to be a problem.' + ddd + 'Please verify your card information.</div>'}); 
        setTimeout(function(){
       remove();
      }, 1000);
    }
  };

Open in new window

0
 
Julian HansenCommented:
why not just do this
<script>
        // Create a reference here - so if the value changes you will get the latest version
        // then use the reference to get the value in the string
        var hsf = document.getElementById('<%= HiddenStatusFlag.ClientID%>');
        var custom1 = function () {
            uglipop({
                class: 'put', //styling class for Modal
                source: 'html',
                content: '<div><br /><br /><br />There seems to be a problem.' + hsf.value + 'Please verify your card information.</div>'
            });
        }
    </script>

Open in new window

If the HidenStatusFlag is a hidden variable with a static value then why not just put that into the string directly?
0
 
Larry Bristersr. DeveloperAuthor Commented:
Julian
On button click there is logic that is applied ...
Right before I call that popup I set that Hidden value

    Protected Sub btnClick_Click(sender As Object, e As EventArgs) Handles btnClick.Click

'blah... blah... blah... code
        HiddenStatusFlag.Value = "TEST"
        ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "script", "$(document).ready(function () { custom1(); });", True)
    End Sub

Open in new window

0
 
Julian HansenCommented:
Then my solution is fine - it should work.
0
 
Larry Bristersr. DeveloperAuthor Commented:
Thanks
0
 
Julian HansenCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now