JavaScript to adjust the size of a div

I have a hidden div in my JSP code that I want to move from one tab to another tab based on the onclick event of the tabs.

<div id="addprojectname" style="-moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    background-color: #FFFFFF;
    border-color: -moz-use-text-color #AAAAAA #AAAAAA;
    border-image: none;
    border-radius: 4px 4px 4px 4px;
    border-style: none solid solid;
    border-width: medium 2px 2px;
    box-shadow: 0 0 5px #AAAAAA;
    display:none;
    width: 328px;">
<form name="frm" action="linkBean.jsp" method="post">
<input type="hidden"  id="sl_category" name="sl_no_cat" >
<table style="padding: 5px 0px 0px 8px;">
<tr>
<th colspan="2">
 <a onclick= "hidewindows('addprojectname');" href="#"><img alt="AALPINE IT SERVICES" src="images/close.png" style="width:20px; float: right; "></a>
</th>
</tr>
<tr>
<th colspan="2">
<div style="width: width:271px; color:red;" id="projectnamevalidate"></div>
</th>
</tr>
<tr>
<th>Project Name<span>:</span></th><td><input type="text"  name="projectname"></td>
</tr>
<tr>
<th>Category Name<span>:</span></th><td><input type="text" id="cost_category" name="category"></td>
</tr>
<tr>
<td colspan="2" style="float:right; padding-top:15px">
<input type="submit" value="Submit" style="width: 60px;">
</td>
</tr>
</table>
</form>
</div>

This is the CSS code:

#addprojectname{
 float: right;
 margin-left: 214px;
 margin-top: 70px;
 position: absolute;

This is the JavaScript code to change the margin value dynamically:

function projectname(id1,id2)
    {
        var userid = document.getElementById(id1).value;
        var e = document.getElementById(id2);
        var url="NameProject.do?id="+userid;
         xmlhttp.open("post", url,true);
         xmlhttp.send(null);
         xmlhttp.onreadystatechange=function()
         {
          if(xmlhttp.readyState==4)
          {       
                 if(xmlhttp.status==200)
                  { 
                     var temp = xmlhttp.responseText;
                    obj = JSON.parse(temp); 
                      if(temp!="")
                      {
                          document.getElementById("cost_category").value=document.getElementById("cost_category").innerHTML=obj.catgoryname;
                          document.getElementById("sl_category").value=document.getElementById("sl_category").innerHTML=obj.sl_no_cat;
                      }
            if(temp!="")
            {
                     if(e.style.display == 'block')
                          e.style.display = 'none';
                     else
                          e.style.display = 'block'; 
            }

            if(temp=="")
              {
                alert("!Data Not existing");
              }
              }
    }
    }

}

Answer №1

Here is a solution you can try:

e.style.marginLeft=myMarginValue;

By implementing this code snippet, you should be able to modify the margin setting as per your request. While I cannot guarantee that it will produce the exact outcome you are looking for, it will definitely accomplish the specific change you have specified.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating visual content on a website

I'm currently working on a project where I need to showcase the results of a numerical model I am operating. My goal is to gather user input in the form of latitude/longitude coordinates, utilize php (or a similar tool) to trigger a python script that ...

Perplexing behavior displayed by non-capturing group in JavaScript regular expressions

Here's a straightforward question for you. Regex can sometimes get tricky, so thank goodness for simplifying things... In the URL, there's a query parameter labeled ?id=0061ecp6cf0q. I want to match it and only retrieve the part after the equal ...

Dynamic form population with dropdown selection using Ajax - Coldfusion continuation

Following some valuable feedback from my previous inquiry, I have made progress: Refer to the original post - Coldfusion Populate form with dropdown selection using ajax Currently, I have successfully sent a request to my CFC with a remote function, but I ...

Retrieve the $scope reference within the $rootScope event handler

Within the .run segment of the primary module in my application, there is an event handler designated for the $locationChangeStart event. Its purpose is to verify the abandonment of any unsaved modifications. The setback lies in the necessity of having a c ...

What is the most effective way to remove a dictionary object in Python?

Currently, I am in possession of a dictionary that requires the removal of a specific element. { "authorizationQualifier": "00", "testIndicator": " ", "functionalGroups": [ { "functiona ...

React Error: Unable to iterate over this.state.descriptions

Currently facing an issue while trying to resolve this error https://i.stack.imgur.com/BZ304.png The goal is to generate an automated form using the following function: let descriptionsForm = ( <form> {this.state.descriptions.map((d ...

Struggling to choose an element by ID and classname?

Currently, I'm diving into the world of HTML and CSS and have encountered a question about selecting elements in CSS. I understand that we use .Classname{} to select a class and #IDname{} to select an ID. But my main confusion lies in trying to selec ...

Retrieve nodes that are children of another node

Here is the code snippet that I am working with: <div id="page1-div" style="position:relative;width:1347px;height:1189px;"> <img width="1347" height="1189" src="target001.png" alt="bac ...

Node.js routing issues leading to rendering failures

I have been working on a website that involves carpooling with drivers and passengers. When a driver submits their details, they are directed to a URL where they can select the passenger they want to ride with. Here is the code snippet I have written: ap ...

Utilizing fab-icons with CDN in Next.js version 13.4

Currently, I am working with the latest version of Next.js (13.4) and I would like to incorporate a single Icon into my project using Font Awesome CDN to avoid increasing the overall app size. However, when I include the following code snippet in my layou ...

How long does it take for Google Docs to respond to a JSON request

I'm facing an issue with a Google Docs spreadsheet that I have set to publish as RSS -> JSON. I've been trying to retrieve the data using the code snippet provided below: public void fetchDataFromDoc() { String url = "https://spreadsheets ...

Sorting data in an Angular JavaScript table by column filters for a combined outcome

I currently have an Angular ngx-datatable that lacks support for filtering by column. My goal is to implement an input filter for each column (which can be strings, multiple choices, etc.) and then merge all these individual filters into a single one. This ...

First render does not define useEffect

Why am I experiencing an issue here? Whenever I attempt to retrieve data from my API, it initially returns undefined during the first render, but subsequent renders work correctly. const [data, setData] = useState([]) useEffect(() => { const fe ...

Guide on converting AS3 to HTML5 while incorporating external AS filesAlternatively: Steps for transforming AS

I've been given the challenging task of transforming a large and complex Flash project into html5 and javaScript. The main stumbling block I'm facing is its heavy reliance on external .as files, leaving me uncertain about the best approach. Most ...

Find the matching objects in two arrays by comparing their unique ids

There are two arrays containing objects. One array includes objects with an id property that holds a list of ids, while the other array contains objects with a unique id property. The goal is to filter the ids in the second array based on the ids in the fi ...

Using Coffeescript to implement mixed objects with magic getters and setters like in Harmony, node-proxy, and other Javascript proxies

I am looking to create a proxied object with methods and private variables attached to it. This means having normal object properties: foo = {} foo.bar = "baz" foo.boo = "hoo" along with some prototypes: foo.setPrivateThings = function(value){ if (valu ...

What is the process for creating a fade out effect with JavaScript?

https://i.sstatic.net/1qgWt.png Is there a way to create a fade out effect in JavaScript? In the image provided, you can see that when you click on a day, a box slides down. If you click on another day, the previous box slides back up while a new box slid ...

The OnChange event seems to be malfunctioning as it is not being triggered despite other parts of the code functioning properly

Check out the code snippet below: import React, { useState } from "react"; function IP() { const [ipAddress, setIPAddress] = useState(""); const handleInputChange = (event) => { const inputValue = event.target.value; // ...

Why are the radio buttons failing to get selected for both questions?

I created a form with 2 questions using Bootstrap. The first question has 4 options, and the second question also has 4 options. I noticed that when I check an option in the first question and then proceed to check an option in the second question, the rad ...

Pair of dimensions painting with d3 version 4

I am having trouble converting my code from d3 v3 to d3 v4 Below is the original code snippet: var brush = d3.svg.brush() .x(x) .y(y) .on("brushstart", brushstart) .on("brush", brushmove) .on("brushend", brushend); However ...