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

Larry Bristersr. DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.