Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8437381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:24:50+00:00 2026-06-10T07:24:50+00:00

Guys I’m new to JavaScript, so not sure where the error is. Basically I’ve

  • 0

Guys I’m new to JavaScript, so not sure where the error is. Basically I’ve two submit buttons in my cshtml. one with the id = email and other id = sms. I’ve set value=” “. I’m using these buttons in a form.

what I want to do is; by clicking on these button I want to pass them a value so that I can use that value in model and controller, like in switch statement. tried various ways but still its passing null value. please advise!

function GetVal() {
    var input = document.getElementsByTagName('input');
    for (i = 0; i < input.length; i++) {
        if (input[i].type == 'submit') {
            if (input[i].id == 'email') {
                //input[i].value = 'submitEmail';
                //input[i].setAttribute("value", "subEmail");
                document.getElementById("email").setAttribute("subEmail", "value");
                break;
            }
        }
    }
}

<input id="email" type="submit" class="@( Model.UnsubscribedEmail == null ? "unsubscribe" : "subscribe")" onclick="GetVal();" />

Model

public static void susbscription(MyModel model, string submitButton)
    {
     switch (submitButton)
        {
            case "subEmail":
            //Code here
            break;
         }
     }

Controller

[HttpPost]
public ActionResult MarketingPreferences(MyModel model, string submitButton)
    {
        MarketingPreferencesModel.susbscription(model, submitButton);

        return View(model);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:24:51+00:00Added an answer on June 10, 2026 at 7:24 am

    Try this:

    <input id="email" type="submit" name="submitButton" onclick="GetVal(this);" class="@( Model.UnsubscribedEmail == null ? "unsubscribe" : "subscribe")"  />
    

    In JavaScript:

    function GetVal(element) {
        element.value = "subEmail";
    }    
    

    In Action:

    public ActionResult MarketingPreferences(MyModel model, string submitButton)
    {
        MarketingPreferencesModel.susbscription(model, submitButton);
    
        return View(model);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys, I am not exactly sure what happens here for the if statement. I
Guys I m using a simple listview. I have two activities one main and
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
guys. I have two view controllers with two uiwebviews. Here is my code: First
Guys I'm new to Android actually, i created an android UI with eclipse, its
guys. In our project, we need to add a new feature which is to
Guys, I've tryied all and had not success. Creating: ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL
guys! There are many Managers in one Organization. Manager - is a child of
Guys when the JVM Crashes it writes an Error Log hs_err_pid.log. I want to
Guys, for some reason EL is not telling actions from properties. I have this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.