Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

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

Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

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

<!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

What string do you want to pass and why?
Avatar of Larry Brister

ASKER

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

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

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Then my solution is fine - it should work.
Thanks
You are welcome.